<?php 
/**
* Test adding existing and uploaded file.
*/
class DomArImageTestCase extends DomArTestUnitTestCase {
	
	public function testCut() {
		
		$o = new DomArTestClass_DomArImage();
		$o->image->addExisting( DOM_MEDIA_DIR . 'DomArImageTestFile.jpg');	
		$this->assertTrue( file_exists(DOMAR_FILE_DEFAULT_PATH.'DomArImageTestFile.jpg') );
		$this->assertEqual( $o->image->getImageSize(), array('width'=>640,'height'=>480));
		
		$o->image->cut(50,50);
		$this->assertEqual( $o->image->getImageSize(), array('width'=>50,'height'=>50));
		
		$o->image->unlink();
		
		
		// ------------------------
		// test validation
		
		/* @TODO CAUSES CRASH ON WINDOWS - NEEDS FIX
		$o = new DomArTestClass_DomArImage();
		$o->image->addExisting( DOM_MEDIA_DIR . 'DomArImageTestBadTextFile.jpg');	
		$this->assertTrue( file_exists(DOMAR_FILE_DEFAULT_PATH.'DomArImageTestBadTextFile.jpg') );
		$this->assertEqual( $o->image->getImageSize(), array('width'=>NULL,'height'=>NULL));
		
		$o->image->cut(50,50);
		$this->assertEqual( $o->image->getImageSize(), array('width'=>NULL,'height'=>NULL));
		
		$i = $o->getValidationInfo();
		$this->assertIdentical( $i[0]['errorNr'], 52 );
		
		$o->image->unlink();
		*/
		
	}
	
	public function testResize() {
		$o = new DomArTestClass_DomArImage();
		$o->image->addExisting( DOM_MEDIA_DIR . 'DomArImageTestFile.jpg');	
		$this->assertTrue( file_exists(DOMAR_FILE_DEFAULT_PATH.'DomArImageTestFile.jpg') );
		$this->assertEqual( $o->image->getImageSize(), array('width'=>640,'height'=>480));
		
		$o->image->resize(320,240);
		$this->assertEqual( $o->image->getImageSize(), array('width'=>320,'height'=>240));
		
		$o->image->resize(100, 120, false);
		$this->assertEqual( $o->image->getImageSize(), array('width'=>160,'height'=>120));
		
		$o->image->unlink();
		
		
		// ------------------------
		// test validation
		/* @TODO CAUSES CRASH ON WINDOWS - NEEDS FIX
		$o = new DomArTestClass_DomArImage();
		$o->image->addExisting( DOM_MEDIA_DIR . 'DomArImageTestBadTextFile.jpg');	
		$this->assertTrue( file_exists(DOMAR_FILE_DEFAULT_PATH.'DomArImageTestBadTextFile.jpg') );
		$this->assertEqual( $o->image->getImageSize(), array('width'=>NULL,'height'=>NULL));
		
		// as this image is bad it will test image sizes, but these are 0,0. On this case resizing never happens, but we really want it to happen :)
		$o->image->resize(-1,-1);
		$this->assertEqual( $o->image->getImageSize(), array('width'=>NULL,'height'=>NULL));
		
		$i = $o->getValidationInfo();
		$this->assertIdentical( $i[0]['errorNr'], 51 );
		
		$o->image->unlink();
		*/
	}
	
	public function testWatermark() {
		
		// ------------------------
		// test validation
		
		$o = new DomArTestClass_DomArImage();
		$o->image->addExisting( DOM_MEDIA_DIR . 'DomArImageTestBadTextFile.jpg');	
		$this->assertTrue( file_exists(DOMAR_FILE_DEFAULT_PATH.'DomArImageTestBadTextFile.jpg') );
		$this->assertEqual( $o->image->getImageSize(), array('width'=>NULL,'height'=>NULL));
		$o->image->watermark('');

		$i = $o->getValidationInfo();
		$this->assertIdentical( $i[0]['errorNr'], 53 );
		
		$o->image->unlink();
	}
	
}
?>